import { customRef } from "vue";

export default function (initvalue: string, delay: number) {

    let timer: number

    let msg = customRef((track, trigger) => {
        return {
            get() {
                track()//告诉vue数据要持续关注
                console.log("get")
                return initvalue
            },
            set(value) {
                clearTimeout(timer)
                console.log("set", value)
                timer = setTimeout(() => {
                    initvalue = value
                    trigger()//通知vue一下数据变化了
                }, delay)

            }
        }
    })

    return { msg }
}